package com.bosssoft.hr.train.j2se.pojo.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.Objects;
import java.util.Set;

/**
 * 用户类
 *
 * @author 史旭升
 * @date 2022-12-06 17:36
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User extends Noun implements Comparable<User> {
    /**
     * 用户所拥有的多个角色，这里采用set不用list是避免role对象重复
     * 当然这个重复判定你hascode和equal的判断字段
     */
    private Set<Role> roles;
    /**
     * 编号
     */
    private String code;
    /**
     * 姓名
     */
    private String name;
    /**
     * 密码
     */
    private String password;
    /**
     * 头像
     */
    private String profilePicture;
    /**
     * 生日 注意采用 Util.date
     */
    private Date birthday;
    /**
     *  电话号码
     */
    private String tel;
    /**
     *  邮箱
     */
    private String email;
    /**
     *  其他
     */
    private String other;
    /**
     * 备注
     */
    private String remark;
    /**
     * 部门id 这里可以考虑组合Department对象
     */
    private Long departmentId;
    /**
     * 职位id 关联职位表 这里可以考虑定位为 Position
     */
    private Long positionId;


    public User(Long id,String name){
        this.id=id;
        this.name=name;
    }

    public User(Long id, Long tenantId, Long orgId, Long companyId, Long createdBy, String creator, Date createdTime, Long updatedBy, Date updatedTime, String modifier, byte status, Long version, Set<Role> roles, String code, String name, String password, String profilePicture, Date birthday, String tel, String email, String other, String remark, Long departmentId, Long positionId) {
        super(id, tenantId, orgId, companyId, createdBy, creator, createdTime, updatedBy, updatedTime, modifier, status, version);
        this.roles = roles;
        this.code = code;
        this.name = name;
        this.password = password;
        this.profilePicture = profilePicture;
        this.birthday = birthday;
        this.tel = tel;
        this.email = email;
        this.other = other;
        this.remark = remark;
        this.departmentId = departmentId;
        this.positionId = positionId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        User user = (User) o;
        return  Objects.equals(id, user.id)&&
                Objects.equals(name, user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), id, name);
    }

    @Override
    public int compareTo(User o) {
        if (this.id > o.id) {
            return -1;
        } else if (this.id.equals(o.id)) {
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", name=" + name +
                '}';
    }
}
